package com.jml.oom;


import java.lang.reflect.Method;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

/**
 * @author:jml
 * @date: 2019/5/8 19:28
 * @description：
 */
public class MetaSpaceDemo {

    static class OOMTest {

    }
    //-XX:MetaspaceSize=8m -XX:MaxMetaspaceSize=8m
    public static void main(String[] args) {
        int i=0;
        try {
            while(true){
                i++;
                Enhancer enhancer = new Enhancer();
                enhancer.setSuperclass(OOMTest.class);
                enhancer.setUseCache(false);
                enhancer.setCallback(new MethodInterceptor() {
                    @Override
                    public Object intercept(Object o, Method method, Object[] objects,
                            MethodProxy methodProxy) throws Throwable {
                        return methodProxy.invokeSuper(o,args);
                    }
                });
                enhancer.create();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("================================"+i);
        }finally {
            System.out.println("================================"+i);
        }
    }
}
